from encodings import normalize_encoding


class Node:
    def __init__(self,data):
        self.data=data
        self.next=None

class CircularLinkedList:
    def __init__(self):
        #初始化头节点
        self.head=Node(0)
        self.head.next=self.head
        self.size=0

    #头插法
    def head_insert(self,data):
        new_node=Node(data)
        new_node.next=self.head.next
        self.head.next=new_node
        self.size+=1

    #尾插法
    def tail_insert(self,data):
        new_node=Node(data)
        current=self.head
        while current.next!=self.head:
            current=current.next
        current.next=new_node
        new_node.next=self.head
        self.size+=1

    #遍历链表
    def print_list(self):
        current=self.head.next
        while current!=self.head:
            print(current.data)
            current=current.next

    #删除节点
    def delete_node(self,data):
        pre_node=self.head
        current=self.head.next
        while current.next!=self.head:
            if current.data==data:
                pre_node.next=current.next
                self.size-=1
                return True
            pre_node=current
            current=current.next
        return False

if __name__=='__main__':
    L=CircularLinkedList()
    L.head_insert(2)
    L.head_insert(1)
    L.tail_insert(3)
    L.tail_insert(4)
    L.delete_node(3)
    L.print_list()
    print('ok')




